 <template>
  <div>
    <van-search
      v-model="value"
      shape="round"
      background="#fff"
      placeholder="请输入搜索关键词"
      @click="showPopup"
    />
    <van-popup
      v-model="show"
      position="right"
      :style="{ height: '100%', width: '100%' }"
    >
      <Popup :isShow="isShow"></Popup>
    </van-popup>

    <!-- 轮播图 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item
        ><img src="~@/assets/images/轮播1.jpg" alt=""
      /></van-swipe-item>
      <van-swipe-item
        ><img src="~@/assets/images/轮播2.jpg" alt=""
      /></van-swipe-item>
      <van-swipe-item
        ><img src="~@/assets/images/轮播3.jpg" alt=""
      /></van-swipe-item>
      <van-swipe-item
        ><img src="~@/assets/images/轮播4.jpg" alt=""
      /></van-swipe-item>
    </van-swipe>
    <!-- 宫格 -->
    <van-grid column-num="5">
      <van-grid-item
        v-for="item in channel"
        :key="item.id"
        :icon="item.icon_url"
        :text="item.name"
        @click="goChannel(item.id)"
      />
    </van-grid>
    <!-- 品牌商 -->
    <div class="brandlist">
      <div class="title">品牌制造商直供</div>
    </div>
    <ul>
      <li v-for="item in brandList" :key="item.id" @click="goBrand(item.id)">
        <img v-lazy="item.pic_url" style="display: block; width: 100%" alt="" />
        <div class="cover">
          <h4>{{ item.name }}</h4>
          <p>￥ {{ item.floor_price }}.00 元</p>
        </div>
      </li>
    </ul>

    <!-- 新品首发 -->
    <div class="first-news">
      <div class="title">周一周四·新品首发</div>
      <ul>
        <li v-for="item in newGoodsList" :key="item.id" @click="goProductdetail(item.id)">

          <img
            v-lazy="item.list_pic_url"
            style="display: block; width: 100%"
            alt=""
          />
          <div class="title">{{ item.name }}</div>
          <div class="price">￥ {{ item.retail_price }}.00 元</div>
        </li>
      </ul>
    </div>
    <!-- 人气精选 -->

    <Person></Person>

    <!-- 专题精选 -->
    <Special></Special>

    <div class="first-news" v-for="item in categoryList" :key="item.id">
      <div class="title">{{ item.name }}</div>
      <ul>
        <li v-for="goods in item.goodsList" :key="goods.id" @click="goProductdetail(item.id)">

          <img
            v-lazy="goods.list_pic_url"
            style="display: block; width: 100%"
            alt=""
          />
          <div class="title">{{ goods.name }}</div>
          <div class="price">￥ {{ goods.retail_price }}.00 元</div>
        </li>
      </ul>
    </div>
    <transition name="slide">
      <router-view v-if="$route.path == '/home/popup'" />
    </transition>
    <BackTop />
  </div>
</template>

<script>
import Popup from "../tsd/Popup.vue";
import Person from "../tsd/Person.vue";
import Special from "../tsd/Special.vue";
import BackTop from "../../components/BackTop.vue";
import { mapGetters } from "vuex";
export default {
  components: {
    Popup,
    Person,
    Special,
    BackTop,
  },
  name: "home",
  data() {
    return {
      active: 0,
      value: "",
      show: false,
    };
  },
  mounted() {
    this.$store.dispatch("getHomeDB");
  },

  computed: {
    ...mapGetters(["channel", "brandList", "newGoodsList", "categoryList"]),
  },
  methods: {
    goBrand(id) {
      this.$router.push("/Brand/" + id);
    },
    goProductdetail(id) {
      this.$router.push("/Productdetail/" + id);
    },
    goChannel(id) {
      this.$router.push("/Channel/" + id);
    },
    showPopup() {
      this.show = true;
    },
    isShow(show) {
      this.show = show;
    },
  },
};
</script>

<style lang="less" scoped>
/* 轮播图样式 */
#app {
  background-color: #ebedf0;
}
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
}
img {
  width: 100%;
  display: block;
}
.cover {
  z-index: 1.3333rem;
}
/* 品牌尚直供 */
.brandlist {
  background: #fff;
  margin-top: 20px;
  /*  margin-bottom: 20px; */
}
.title {
  text-align: center;
  height: 50px;
  line-height: 50px;
  font-size: 12px;
  text-overflow: ellipsis;
}
ul {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  list-style: none;
  background-color: #fff;
}
ul > li {
  width: 49%;
  margin-bottom: 2px;
  position: relative;
}
h4 {
  display: block;
  position: absolute;
  left: 0.1rem;
  top: 10px;
  font-weight: normal;
}

p {
  display: block;
  position: absolute;
  left: 0.1rem;
  top: 40px;
  color: darkred;
}
/* 新品首发 */

.first-news {
  margin-top: 20px;
  background: #fff;
}
.price {
  color: #8b0000;
  text-align: center;
}

.homecategory {
  background: #fff;
  margin-top: 20px;
}
.price {
  color: #8b0000;
  text-align: center;
}

.homecategory {
  background: #fff;
  margin-top: 20px;
}

.slide-enter,
.slide-leave-to {
  right: -100%;
}
.price {
  color: #8b0000;
  text-align: center;
}

.homecategory {
  background: #fff;
  margin-top: 20px;
}
/* 首页内容的淡出 */
.myfade-leave {
  opacity: 1;
}
.myfade-leave-active {
  transition: opacity 0.5s linear;
}
.myfade-leave-to {
  opacity: 0;
}

/* 只要淡入 */
.myfade1-enter,
.myfade1-leave-to {
  opacity: 0;
}
.myfade1-enter-active,
.myfade1-leave-active {
  transition: opacity 0.5s linear;
}
.myfade1-enter-to,
.myfade1-leave {
  opacity: 1;
}
</style>